//
//  ReplyMineCellView.m
//  JiaoX
//
//  Created by yinqy on 15/2/27.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "ReplyMineView.h"
#import "MineInteract.h"
@interface ReplyMineView()
/** 头像 */
@property (nonatomic ,weak) UIImageView *headImg;
/** 名称 */
@property (nonatomic, weak) UILabel *nameLabel;
/** 时间 */
@property (nonatomic, weak) UIButton *timeBtn;
/** 箭头 */
@property (nonatomic, weak) UIImageView *arrowImg;
/** 回复内容 */
@property (nonatomic, weak) UILabel *replyContentLabel;

@property (nonatomic, weak) UIView *replyFromBg;

@property (nonatomic, weak) UILabel *replyFrom;

@end
@implementation ReplyMineView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *headImg = [[UIImageView alloc]init];
        [self addSubview:headImg];
        self.headImg = headImg;
        
        UILabel *nameLabel = [[UILabel alloc]init];
        [nameLabel setFont:[UIFont systemFontOfSize:NAMELABEL_FONT_SIZE]];
        [nameLabel setTextColor:JXColor(75, 75, 75)];
        [self addSubview:nameLabel];
        self.nameLabel = nameLabel;
        
        UIButton *timeBtn = [[UIButton alloc]init];
        [timeBtn.titleLabel setFont:[UIFont systemFontOfSize:TIMELABEL_FONT_SIZE]];
        [timeBtn setTitleColor:JXColor(153, 153, 153) forState:UIControlStateNormal];
        [timeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
        [timeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
        [timeBtn setImage:[UIImage imageNamed:@"ic_time"] forState:UIControlStateNormal];
        [self addSubview:timeBtn];
        self.timeBtn = timeBtn;
        
        UIImageView *arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"self_item_arrow"]];
        [self addSubview:arrowImg];
        self.arrowImg = arrowImg;
        
        UILabel *replyContentLabel = [[UILabel alloc]init];
        [replyContentLabel setTextColor:[UIColor blackColor]];
        [replyContentLabel setFont:[UIFont systemFontOfSize:REPLYCONTENTLABEL_FONT_SIZE]];
        [self addSubview:replyContentLabel];
        self.replyContentLabel = replyContentLabel;
        
        UIView *replyFromBg = [[UIView alloc]init];
        [replyFromBg setBackgroundColor:JXColorAlpha(204, 204, 204,100)];
        [self addSubview:replyFromBg];
        self.replyFromBg = replyFromBg;
        
        UILabel *replyFrom = [[UILabel alloc]init];
        [replyFrom setTextColor:JXColor(77, 77, 77)];
        [replyFrom setFont:[UIFont systemFontOfSize:REPLYFROM_FONT_SIZE]];
        [self.replyFromBg addSubview:replyFrom];
        self.replyFrom = replyFrom;
        
    }
    return self;
}

-(void)setReplymineCellFrame:(ReplyMineCellFrame *)replymineCellFrame{
    self.frame = replymineCellFrame.frame;
    
    self.headImg.frame = replymineCellFrame.headImgFrame;
    [self.headImg.layer setCornerRadius:self.headImg.width/2];
    [self.headImg.layer setMasksToBounds:YES];
    [self.headImg sd_setImageWithURL:[NSURL URLWithString:replymineCellFrame.mineInteract.userInfo.userImg]];
    
    self.nameLabel.frame = replymineCellFrame.nameLabelFrame;
    [self.nameLabel setText:replymineCellFrame.mineInteract.userInfo.nickName];
    
    self.timeBtn.frame = replymineCellFrame.timeLabelFrame;
    [self.timeBtn setTitle:replymineCellFrame.mineInteract.createTime forState:UIControlStateNormal];
    
    self.arrowImg.x = JXScreenW-JXPublicInset-self.arrowImg.width;
    self.arrowImg.y = self.timeBtn.centerY-self.arrowImg.height/2;
    
    self.replyContentLabel.frame = replymineCellFrame.replyContentFrame;
    [self.replyContentLabel setText:replymineCellFrame.mineInteract.content];
    
    self.replyFromBg.frame = replymineCellFrame.replyFromBgFrame;
    
    self.replyFrom.frame = replymineCellFrame.replyFromFrame;
    NSString *replyFrom = @"";
    if ([replymineCellFrame.replyType isEqualToString:@"0"]) {
        replyFrom = [NSString stringWithFormat:@"回复我的帖子：%@",replymineCellFrame.mineInteract.postsTitle];
    }else if([replymineCellFrame.replyType isEqualToString:@"1"]){
        replyFrom = [NSString stringWithFormat:@"回复我的评论：%@",replymineCellFrame.mineInteract.mainComment.commentContent];
    }
    
    NSMutableDictionary *rangs = [NSMutableDictionary dictionary];
    [rangs setObject:JXColor(153, 153, 153) forKey:NSStringFromRange(NSMakeRange(0, 7))];
    [self.replyFrom setAttributedText:[Utils getAttribtString:replyFrom attrRangs:rangs]];
    
}
@end
